import store from '../../store'

export default {
  name: 'History',
  data () {
    return {
      tableData: []
    }
  },
  mounted () {
    store.dispatch('orderList', store.state.user.id)
      .then(response => {
        this.tableData = response.data
        for (var i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].type === 0) {
            this.tableData[i].orderType = '买入'
          } else if (this.tableData[i].type === 1) {
            this.tableData[i].orderType = '卖出'
          }
          this.tableData[i].date = this.tableData[i].datetime.substring(0, 10)
        }
      })
      .catch(error => {
        console.log('connect failed')
        console.log(error)
      })
  }
}
